package com.zking.ssm.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zking.ssm.sys.mapper.RoleMapper;
import com.zking.ssm.sys.model.Role;
import com.zking.ssm.sys.service.IRoleService;
import com.zking.ssm.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    public RoleServiceImpl() {

    }

    @Override
    public int deleteByPrimaryKey(Long roleId) {
        return roleMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public int insert(Role record) {
        return roleMapper.insert(record);
    }

    @Override
    public int insertSelective(Role record) {
        return roleMapper.insertSelective(record);
    }

    @Override
    public Role selectByPrimaryKey(Long roleId) {
        return roleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public int updateByPrimaryKeySelective(Role record) {
        return roleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Role record) {
        return roleMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Role> list(Role role, PageBean pageBean) {
        if (null != pageBean && 0 != pageBean.getRows()) {
            PageHelper.startPage(pageBean.getPage(), pageBean.getRows());
        }
        List<Role> roleList = roleMapper.list(role);
        if (null != pageBean && 0 != pageBean.getRows()) {
            PageInfo pageInfo = new PageInfo(roleList);
            pageBean.setTotal(pageInfo.getTotal() + "");
        }

        return roleList;
    }
}
